let app = new Vue({
    el: "#app",
    data: {
        message: "Hello Vue!",
        show: false,
        dict: {
            type: ['mysql']
        },
        formData: {
            connectInfoLeft: {
                ip: null,
                type: null,
                port: null,
                database: null,
                username: null,
                password: null
            },
            connectInfoRight: {
                ip: null,
                type: null,
                port: null,
                database: null,
                username: null,
                password: null
            }
        },
        selectedTablesLeft: [],
        selectedTablesRight: [],
        tablesInfoLeft: [],
        tablesInfoRight: [],
        opened: false,
        tableDetailInfo: {},
        fieldsList: [],
        result: [],
        rules: {
            number: ['number'],
            mobile: ['mobile'],
            required: ['ip', 'type','port','database','username','password']
        }
    },
    watch: {},
    methods: {
        openModal: function () {
            this.$Modal({
                title: "title",
                content: "This is a js call box"
            });
        },
        test: function (direction, leftDat, rightData) {

        },
        trSelectLeft: function (data) {
            this.selectedTablesLeft = data;
        },
        trSelectRight: function (data) {
            this.selectedTablesRight = data;
        },
        connect: function (flag) {
            if (flag === 'left') {
                let validResult = this.$refs.formLeft.valid();
                if (validResult.result) {
                    this.connectLeft();
                }
            }
            if (flag === 'right') {
                let validResult = this.$refs.formRight.valid();
                if (validResult.result) {
                    this.connectRight();
                }
            }

        },
        connectLeft: function () {
            let that = this;
            axios.post('/qryTables', that.formData.connectInfoLeft).then(function (res) {
                that.tablesInfoLeft = res.data;
                console.log(res.data)
            }).catch(function (error) {
                that.$Message({
                    type: 'error',
                    text: "获取表信息异常:" + error
                });
            })
        },
        connectRight: function () {
            let that = this;
            axios.post('/qryTables', that.formData.connectInfoRight).then(function (res) {
                that.tablesInfoRight = res.data;
            }).catch(function (error) {
                that.$Message({
                    type: 'error',
                    text: "获取表信息异常:" + error
                });
            })
        },
        tableInfoDetailLeft: function (datas, data) {
            this.opened = true;
            this.tableDetailInfo = data;
            this.qryFieldsLeft(data.TABLE_NAME);
        },
        tableInfoDetailRight: function (datas, data) {
            this.opened = true;
            this.tableDetailInfo = data;
            this.qryFieldsRight(data.TABLE_NAME);
        },

        qryFieldsLeft: function (tableName) {
            let that = this;
            let params = {
                dbInfo: this.formData.connectInfoLeft,
                tableName: tableName
            }
            axios.post('/qryFields', params).then(function (res) {
                that.fieldsList = res.data;
                console.log(res.data)
            }).catch(function (error) {
                that.$Message({
                    type: 'error',
                    text: "获取字段息异常:" + error
                });
            })
        },
        qryFieldsRight: function (tableName) {
            let that = this;
            let params = {
                dbInfo: this.formData.connectInfoRight,
                tableName: tableName
            }
            axios.post('/qryFields', params).then(function (res) {
                that.fieldsList = res.data;
            }).catch(function (error) {
                that.$Message({
                    type: 'error',
                    text: "获取字段息异常:" + error
                });
            })
        },

        compare: function () {
            let that = this;
            if (this.selectedTablesLeft.length === 0 && this.selectedTablesRight.length === 0) {
                return;
            }
            that.result = [];
            let leftTableInfo = this.selectedTablesLeft;
            let rightTableInfo = this.selectedTablesRight;
            //左对比右

           // if (leftTableInfo.length >= rightTableInfo.length)
                for (let i in leftTableInfo) {
                    let hasTable = false;
                    for (let j in rightTableInfo) {
                        let leftTable = leftTableInfo[i];
                        let rightTable = rightTableInfo[j];
                        let leftTableName = leftTable['TABLE_NAME'];
                        let rightTableName = rightTable['TABLE_NAME']
                        if (leftTableName === rightTableName) {
                            hasTable = true;
                            //查询字段(左)
                            let paramsLeft = {
                                dbInfo: that.formData.connectInfoLeft,
                                tableName: leftTable['TABLE_NAME']
                            };
                            $.ajax({
                                url: '/qryFields',
                                data: JSON.stringify(paramsLeft),
                                dataType: 'json',
                                type: 'post',
                                contentType: 'application/json',
                                async: false,
                                success: function (res) {
                                    let leftFields = res;
                                    that.selectedTablesLeft[i].fields = leftFields;
                                    //查询字段(右)
                                    let paramsRight = {
                                        dbInfo: that.formData.connectInfoRight,
                                        tableName: rightTable['TABLE_NAME']
                                    };
                                    $.ajax({
                                        url: '/qryFields',
                                        data: JSON.stringify(paramsRight),
                                        dataType: 'json',
                                        type: 'post',
                                        contentType: 'application/json',
                                        async: false,
                                        success: function (res) {
                                            let rightFields = res;
                                            that.selectedTablesRight[i].fields = rightFields;

                                            for (let idxL in leftFields) {
                                                let exits = false;
                                                let nL = leftFields[idxL]['Field'];
                                                for (let idxR in rightFields) {
                                                    let nR = rightFields[idxR]['Field'];
                                                    if (nL === nR) {
                                                        exits = true;
                                                        let idx = idxL;
                                                        let lf = leftFields[idx];
                                                        let rf = rightFields[idx];
                                                        if (lf['Field'] === rf['Field']) {
                                                            for (let key in lf) {
                                                                if (lf[key] !== rf[key]) {
                                                                    that.selectedTablesLeft[i].dif = 'true';
                                                                    that.selectedTablesRight[i].dif = 'true';
                                                                    that.selectedTablesLeft[i].des = that.selectedTablesLeft[i].des === undefined ? new Set(['差异字段']) : that.selectedTablesLeft[i].des.add('差异字段');
                                                                    that.selectedTablesRight[i].des = that.selectedTablesRight[i].des === undefined ? new Set(['差异字段']) : that.selectedTablesRight[i].des.add('差异字段');
                                                                    that.selectedTablesLeft[i].fields[idx].dif = 'true';
                                                                    that.selectedTablesRight[i].fields[idx].dif = 'true';
                                                                    that.selectedTablesLeft[i].fields[idx].difType = that.selectedTablesLeft[i].fields[idx].difType === undefined ? new Set([key]) : that.selectedTablesLeft[i].fields[idx].difType.add(key);
                                                                    that.selectedTablesRight[i].fields[idx].difType = that.selectedTablesRight[i].fields[idx].difType === undefined ? new Set([key]) : that.selectedTablesRight[i].fields[idx].difType.add(key);

                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                if (!exits) {
                                                    that.selectedTablesLeft[i].dif = 'true';
                                                    that.selectedTablesRight[i].dif = 'true';
                                                    that.selectedTablesLeft[i].des = that.selectedTablesLeft[i].des === undefined ? new Set(['缺失或增加字段']) : that.selectedTablesLeft[i].des.add('缺失或增加字段');
                                                    that.selectedTablesRight[i].des = that.selectedTablesRight[i].des === undefined ? new Set(['缺失或增加字段']) : that.selectedTablesRight[i].des.add('缺失或增加字段');
                                                    that.selectedTablesLeft[i].fields[idxL].dif = 'true';
                                                    that.selectedTablesLeft[i].fields[idxL].missOrAdd = 'true';
                                                }
                                            }
                                            for (let idxR in rightFields) {
                                                let exits = false;
                                                let nR = rightFields[idxR]['Field'];
                                                for (let idxL in leftFields) {
                                                    let nL = leftFields[idxL]['Field'];
                                                    if (nL === nR) {
                                                        exits = true;
                                                        let idx = idxR;
                                                        let lf = leftFields[idx];
                                                        let rf = rightFields[idx];
                                                        if (lf['Field'] === rf['Field']) {
                                                            for (let key in lf) {
                                                                if (lf[key] !== rf[key]) {
                                                                    that.selectedTablesLeft[i].dif = 'true';
                                                                    that.selectedTablesRight[i].dif = 'true';
                                                                    that.selectedTablesLeft[i].des = that.selectedTablesLeft[i].des === undefined ? new Set(['差异字段']) : that.selectedTablesLeft[i].des.add('差异字段');
                                                                    that.selectedTablesRight[i].des = that.selectedTablesRight[i].des === undefined ? new Set(['差异字段']) : that.selectedTablesRight[i].des.add('差异字段');
                                                                    that.selectedTablesLeft[i].fields[idx].dif = 'true';
                                                                    that.selectedTablesRight[i].fields[idx].dif = 'true';
                                                                    that.selectedTablesLeft[i].fields[idx].difType = that.selectedTablesLeft[i].fields[idx].difType === undefined ? new Set([key]) : that.selectedTablesLeft[i].fields[idx].difType.add(key);
                                                                    that.selectedTablesRight[i].fields[idx].difType = that.selectedTablesRight[i].fields[idx].difType === undefined ? new Set([key]) : that.selectedTablesRight[i].fields[idx].difType.add(key);
                                                                }
                                                            }
                                                        }
                                                    }

                                                }
                                                if (!exits) {
                                                    that.tablesInfoLeft[i].dif = 'true';
                                                    that.selectedTablesRight[i].dif = 'true';
                                                    that.tablesInfoLeft[i].des = that.tablesInfoLeft[i].des === undefined ? new Set(['缺失或增加字段']) : that.tablesInfoLeft[i].des.add('缺失或增加字段');
                                                    that.selectedTablesRight[i].des = that.selectedTablesRight[i].des === undefined ? new Set(['缺失或增加字段']) : that.selectedTablesRight[i].des.add('缺失或增加字段');
                                                    that.selectedTablesRight[i].fields[idxR].dif = 'true';
                                                    that.selectedTablesRight[i].fields[idxR].missOrAdd = 'true';
                                                }
                                            }
                                        }
                                    });
                                }
                            })
                        }
                    }
                    if (!hasTable) {
                        that.result.push({left: that.selectedTablesLeft[i], right: {fields:[]}});
                    } else
                        that.result.push({left: that.selectedTablesLeft[i], right: that.selectedTablesRight[i]});

                }
            //反之
         /*   if (leftTableInfo.length < rightTableInfo.length)
                for (let i in rightTableInfo) {
                    let hasTable = false;
                    for (let j in leftTableInfo) {
                        let leftTable = leftTableInfo[j];
                        let rightTable = rightTableInfo[i];
                        let leftTableName = leftTable['TABLE_NAME'];
                        let rightTableName = rightTable['TABLE_NAME']
                        if (leftTableName === rightTableName) {
                            hasTable = true;
                            //查询字段(左)
                            let paramsLeft = {
                                dbInfo: that.formData.connectInfoLeft,
                                tableName: leftTable['TABLE_NAME']
                            };
                            $.ajax({
                                url: '/qryFields',
                                data: JSON.stringify(paramsLeft),
                                dataType: 'json',
                                type: 'post',
                                contentType: 'application/json',
                                async: false,
                                success: function (res) {
                                    let leftFields = res;
                                    that.selectedTablesLeft[i].fields = leftFields;
                                    //查询字段(右)
                                    let paramsRight = {
                                        dbInfo: that.formData.connectInfoRight,
                                        tableName: rightTable['TABLE_NAME']
                                    };
                                    $.ajax({
                                        url: '/qryFields',
                                        data: JSON.stringify(paramsRight),
                                        dataType: 'json',
                                        type: 'post',
                                        contentType: 'application/json',
                                        async: false,
                                        success: function (res) {
                                            let rightFields = res;
                                            that.selectedTablesRight[i].fields = rightFields;

                                            for (let idxL in leftFields) {
                                                let exits = false;
                                                let nL = leftFields[idxL]['Field'];
                                                for (let idxR in rightFields) {
                                                    let nR = rightFields[idxR]['Field'];
                                                    if (nL === nR) {
                                                        exits = true;
                                                        let idx = idxL;
                                                        let lf = leftFields[idx];
                                                        let rf = rightFields[idx];
                                                        if (lf['Field'] === rf['Field']) {
                                                            for (let key in lf) {
                                                                if (lf[key] !== rf[key]) {
                                                                    that.selectedTablesLeft[i].dif = 'true';
                                                                    that.selectedTablesRight[i].dif = 'true';
                                                                    that.selectedTablesLeft[i].des = that.selectedTablesLeft[i].des === undefined ? new Set(['差异字段']) : that.selectedTablesLeft[i].des.add('差异字段');
                                                                    that.selectedTablesRight[i].des = that.selectedTablesRight[i].des === undefined ? new Set(['差异字段']) : that.selectedTablesRight[i].des.add('差异字段');
                                                                    that.selectedTablesLeft[i].fields[idx].dif = 'true';
                                                                    that.selectedTablesRight[i].fields[idx].dif = 'true';
                                                                    that.selectedTablesLeft[i].fields[idx].difType = that.selectedTablesLeft[i].fields[idx].difType === undefined ? new Set([key]) : that.selectedTablesLeft[i].fields[idx].difType.add(key);
                                                                    that.selectedTablesRight[i].fields[idx].difType = that.selectedTablesRight[i].fields[idx].difType === undefined ? new Set([key]) : that.selectedTablesRight[i].fields[idx].difType.add(key);

                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                if (!exits) {
                                                    that.selectedTablesLeft[i].dif = 'true';
                                                    that.selectedTablesRight[i].dif = 'true';
                                                    that.selectedTablesLeft[i].des = that.selectedTablesLeft[i].des === undefined ? new Set(['缺失或增加字段']) : that.selectedTablesLeft[i].des.add('缺失或增加字段');
                                                    that.selectedTablesRight[i].des = that.selectedTablesRight[i].des === undefined ? new Set(['缺失或增加字段']) : that.selectedTablesRight[i].des.add('缺失或增加字段');
                                                    that.selectedTablesLeft[i].fields[idxL].dif = 'true';
                                                    that.selectedTablesLeft[i].fields[idxL].missOrAdd = 'true';
                                                }
                                            }

                                            for (let idxR in rightFields) {
                                                let exits = false;
                                                let nR = rightFields[idxR]['Field'];
                                                for (let idxL in leftFields) {
                                                    let nL = leftFields[idxL]['Field'];
                                                    if (nL === nR) {
                                                        exits = true;
                                                        let idx = idxR;
                                                        let lf = leftFields[idx];
                                                        let rf = rightFields[idx];
                                                        if (lf['Field'] === rf['Field']) {
                                                            for (let key in lf) {
                                                                if (lf[key] !== rf[key]) {
                                                                    that.selectedTablesLeft[i].dif = 'true';
                                                                    that.selectedTablesRight[i].dif = 'true';
                                                                    that.selectedTablesLeft[i].des = that.selectedTablesLeft[i].des === undefined ? new Set(['差异字段']) : that.selectedTablesLeft[i].des.add('差异字段');
                                                                    that.selectedTablesRight[i].des = that.selectedTablesRight[i].des === undefined ? new Set(['差异字段']) : that.selectedTablesRight[i].des.add('差异字段');
                                                                    that.selectedTablesLeft[i].fields[idx].dif = 'true';
                                                                    that.selectedTablesRight[i].fields[idx].dif = 'true';
                                                                    that.selectedTablesLeft[i].fields[idx].difType = that.selectedTablesLeft[i].fields[idx].difType === undefined ? new Set([key]) : that.selectedTablesLeft[i].fields[idx].difType.add(key);
                                                                    that.selectedTablesRight[i].fields[idx].difType = that.selectedTablesRight[i].fields[idx].difType === undefined ? new Set([key]) : that.selectedTablesRight[i].fields[idx].difType.add(key);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                if (!exits) {
                                                    that.tablesInfoLeft[i].dif = 'true';
                                                    that.selectedTablesRight[i].dif = 'true';
                                                    that.tablesInfoLeft[i].des = that.tablesInfoLeft[i].des === undefined ? new Set(['缺失或增加字段']) : that.tablesInfoLeft[i].des.add('缺失或增加字段');
                                                    that.selectedTablesRight[i].des = that.selectedTablesRight[i].des === undefined ? new Set(['缺失或增加字段']) : that.selectedTablesRight[i].des.add('缺失或增加字段');
                                                    that.selectedTablesRight[i].fields[idxR].dif = 'true';
                                                    that.selectedTablesRight[i].fields[idxR].missOrAdd = 'true';
                                                }
                                            }
                                        }
                                    });
                                }
                            })
                        }

                    }
                    if (!hasTable) {
                        //that.selectedTablesRight[i]
                    } else
                        that.result.push({right: that.selectedTablesLeft[i], left: that.selectedTablesRight[i]});
                }*/
            /* for (let j in  rightTableInfo) {
                 for (let i in leftTableInfo) {
                     let leftTable = leftTableInfo[i];
                     let rightTable = rightTableInfo[j];
                     let leftTableName = leftTable['TABLE_NAME'];
                     let rightTableName = rightTable['TABLE_NAME']
                     if (leftTableName === rightTableName) {
                         //查询字段(左)
                         let paramsLeft = {
                             dbInfo: that.formData.connectInfoLeft,
                             tableName: leftTable['TABLE_NAME']
                         };
                         $.ajax({
                             url: '/qryFields',
                             data: JSON.stringify(paramsLeft),
                             dataType: 'json',
                             type: 'post',
                             contentType: 'application/json',
                             async: false,
                             success: function (res) {
                                 let leftFields = res;
                                 that.selectedTablesLeft[j].fields = leftFields;
                                 //查询字段(右)
                                 let paramsRight = {
                                     dbInfo: that.formData.connectInfoRight,
                                     tableName: rightTable['TABLE_NAME']
                                 };
                                 $.ajax({
                                     url: '/qryFields',
                                     data: JSON.stringify(paramsRight),
                                     dataType: 'json',
                                     type: 'post',
                                     contentType: 'application/json',
                                     async: false,
                                     success: function (res) {
                                         let rightFields = res;
                                         that.selectedTablesRight[j].fields = rightFields;

                                         for (let idxL in leftFields) {
                                             let exits = false;
                                             let nL = leftFields[idxL]['Field'];
                                             for (let idxR in rightFields) {
                                                 let nR = rightFields[idxR]['Field'];
                                                 if (nL === nR) {
                                                     exits = true;
                                                     let idx = idxL;
                                                     let lf = leftFields[idx];
                                                     let rf = rightFields[idx];
                                                     if (lf['Field'] === rf['Field']) {
                                                         for (let key in lf) {
                                                             if (lf[key] !== rf[key]) {
                                                                 that.selectedTablesLeft[j].dif = 'true';
                                                                 that.selectedTablesRight[j].dif = 'true';
                                                                 that.selectedTablesLeft[j].des = that.selectedTablesLeft[j].des === undefined ? new Set(['差异字段']) : that.selectedTablesLeft[j].des.add('差异字段');
                                                                 that.selectedTablesRight[j].des = that.selectedTablesRight[j].des === undefined ? new Set(['差异字段']) : that.selectedTablesRight[j].des.add('差异字段');
                                                                 that.selectedTablesLeft[j].fields[idx].dif = 'true';
                                                                 that.selectedTablesRight[j].fields[idx].dif = 'true';
                                                                 that.selectedTablesLeft[j].fields[idx].difType= that.selectedTablesLeft[j].fields[idx].difType=== undefined ? new Set([key]):that.selectedTablesLeft[j].fields[idx].difType.add(key) ;
                                                                 that.selectedTablesRight[j].fields[idx].difType= that.selectedTablesRight[j].fields[idx].difType=== undefined ? new Set([key]):that.selectedTablesRight[j].fields[idx].difType.add(key) ;

                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                             if (!exits) {
                                                 that.selectedTablesLeft[j].dif = 'true';
                                                 that.selectedTablesRight[j].dif = 'true';
                                                 that.selectedTablesLeft[j].des = that.selectedTablesLeft[j].des === undefined ? new Set(['缺失或增加字段']) : that.selectedTablesLeft[j].des.add('缺失或增加字段');
                                                 that.selectedTablesRight[j].des = that.selectedTablesRight[j].des === undefined ? new Set(['缺失或增加字段']) : that.selectedTablesRight[j].des.add('缺失或增加字段');
                                                 that.selectedTablesLeft[j].fields[idxL].dif = 'true';
                                                 that.selectedTablesLeft[j].fields[idxL].missOrAdd = 'true';
                                             }
                                         }
                                         for (let idxR in rightFields) {
                                             let exits = false;
                                             let nR = rightFields[idxR]['Field'];
                                             for (let idxL in leftFields) {
                                                 let nL = leftFields[idxL]['Field'];
                                                 if (nL === nR) {
                                                     exits = true;
                                                     let idx = idxR;
                                                     let lf = leftFields[idx];
                                                     let rf = rightFields[idx];
                                                     if (lf['Field'] === rf['Field']) {
                                                         for (let key in lf) {
                                                             if (lf[key] !== rf[key]) {
                                                                 that.selectedTablesLeft[j].dif = 'true';
                                                                 that.selectedTablesRight[j].dif = 'true';
                                                                 that.selectedTablesLeft[j].des = that.selectedTablesLeft[j].des === undefined ? new Set(['差异字段']) : that.selectedTablesLeft[j].des.add('差异字段');
                                                                 that.selectedTablesRight[j].des = that.selectedTablesRight[j].des === undefined ? new Set(['差异字段']) : that.selectedTablesRight[j].des.add('差异字段');
                                                                 that.selectedTablesLeft[j].fields[idx].dif = 'true';
                                                                 that.selectedTablesRight[j].fields[idx].dif = 'true';
                                                                 that.selectedTablesLeft[j].fields[idx].difType= that.selectedTablesLeft[j].fields[idx].difType=== undefined ? new Set([key]):that.selectedTablesLeft[j].fields[idx].difType.add(key) ;
                                                                 that.selectedTablesRight[j].fields[idx].difType= that.selectedTablesRight[j].fields[idx].difType=== undefined ? new Set([key]):that.selectedTablesRight[j].fields[idx].difType.add(key) ;
                                                             }
                                                         }
                                                     }
                                                 }

                                             }
                                             if (!exits) {
                                                 that.tablesInfoLeft[j].dif = 'true';
                                                 that.selectedTablesRight[j].dif = 'true';
                                                 that.tablesInfoLeft[j].des = that.tablesInfoLeft[j].des === undefined ? new Set(['缺失或增加字段']) : that.tablesInfoLeft[j].des.add('缺失或增加字段');
                                                 that.selectedTablesRight[j].des = that.selectedTablesRight[j].des === undefined ? new Set(['缺失或增加字段']) : that.selectedTablesRight[j].des.add('缺失或增加字段');
                                                 that.selectedTablesRight[j].fields[idxR].dif = 'true';
                                                 that.selectedTablesRight[j].fields[idxR].missOrAdd = 'true';
                                             }
                                         }
                                     }
                                 });
                             }
                         })
                     }
                 }

                 that.result.push({left: that.selectedTablesLeft[j], right: that.selectedTablesRight[j]});

             }*/
            console.log(that.result);
        },
        parseDes: function (data) {
            let res = [];
            if (data.des !== undefined) {
                data.des.forEach(function (ele) {
                    res.push(ele);
                })
                return '(' + res.join(',') + ')';
            }
            return '';
        },
        parseFieldDes: function (key, data) {
            let uuid = data['_heyui_uuid'];
            let isDif = false;
            if (data.difType !== undefined) {
                data.difType.forEach(function (ele) {
                    if (key === ele) {
                        isDif = true;

                    }
                })
            }
            if (data.missOrAdd === 'true') {
                $('tr[trindex="' + uuid + '"]').addClass('bg-blue-color white-color');
            } else if (data.dif === 'true') {
                $('tr[trindex="' + uuid + '"]').addClass('bg-yellow-color white-color');
            }

            if (isDif) {

                return '<span class="red-color text-ellipsis">' + data[key] + '</span>';
            } else {
                return '<span >' + data[key] + '</span>';
            }
        },
        resultDetail: function (data) {
            this.$set(data, '_expand', !data._expand);
        },
        formatTime: function (date) {
            let fmt = 'yyyy-MM-dd hh:mm:ss';
            let o = {
                "M+": date.getMonth() + 1,                 //月份
                "d+": date.getDate(),                    //日
                "h+": date.getHours(),                   //小时
                "m+": date.getMinutes(),                 //分
                "s+": date.getSeconds(),                 //秒
                "q+": Math.floor((date.getMonth() + 3) / 3), //季度
                "S": date.getMilliseconds()             //毫秒
            };
            if (/(y+)/.test(fmt))
                fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (let k in o)
                if (new RegExp("(" + k + ")").test(fmt))
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        }
    }
});